package mobi.greenplate.client.converter;

import mobi.greenplate.client.domain.User;
import mobi.greenplate.client.domain.UserRole;
import mobi.greenplate.client.domain.UserType;

/**
 *
 * @author dmakariev
 */
public class UserConverter {

    private UserConverter() {
    }
    private static final String ID = "id";
    private static final String PASSWORD = "password";
    private static final String USERNAME = "userName";
    private static final String TYPE = "type";
    private static final String USERROLE = "userRole";

    public static User endTag(User user, String tagName, String text) {
        if (tagName.equalsIgnoreCase(ID)) {
            user.setId(Long.valueOf(text));
        } else if (tagName.equalsIgnoreCase(PASSWORD)) {
            user.setPassword(text);
        } else if (tagName.equalsIgnoreCase(USERNAME)) {
            user.setUserName(text);
        } else if (tagName.equalsIgnoreCase(TYPE)) {
            user.setType(UserType.valueOf(text));
        } else if (tagName.equalsIgnoreCase(USERROLE)) {
            user.setUserRole(UserRole.valueOf(text));
        }
        return user;
    }
}
